package com.icoolkj.ms.common.core.utils.file;

import lombok.AccessLevel;
import lombok.NoArgsConstructor;

/**
 * 媒体类型工具类
 * 
 * @author icoolkj
 */
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public class MimeTypeUtils {
    
    /**
     * 图片扩展名
     */
    public static final String[] IMAGE_EXTENSION = {"bmp", "gif", "jpg", "jpeg", "png"};

    /**
     * 文档扩展名
     */
    public static final String[] DOCUMENT_EXTENSION = {"doc", "docx", "xls", "xlsx", "ppt", "pptx", "pdf", "txt"};

    /**
     * 音视频扩展名
     */
    public static final String[] MEDIA_EXTENSION = {"mp3", "mp4", "flv", "avi", "rmvb", "wav"};

    /**
     * 压缩文件扩展名
     */
    public static final String[] COMPRESS_EXTENSION = {"rar", "zip", "gz", "bz2", "7z"};

    /**
     * 图片类型
     */
    public static final String IMAGE_PNG = "image/png";
    public static final String IMAGE_JPG = "image/jpg";
    public static final String IMAGE_JPEG = "image/jpeg";
    public static final String IMAGE_BMP = "image/bmp";
    public static final String IMAGE_GIF = "image/gif";

    /**
     * 文档类型
     */
    public static final String DOC_PDF = "application/pdf";
    public static final String DOC_MSWORD = "application/msword";
    public static final String DOC_MSEXCEL = "application/vnd.ms-excel";
    public static final String DOC_MSPPT = "application/vnd.ms-powerpoint";
    public static final String DOC_DOCX = "application/vnd.openxmlformats-officedocument.wordprocessingml.document";
    public static final String DOC_XLSX = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
    public static final String DOC_PPTX = "application/vnd.openxmlformats-officedocument.presentationml.presentation";
    public static final String DOC_TXT = "text/plain";

    /**
     * 音视频类型
     */
    public static final String MEDIA_MP3 = "audio/mp3";
    public static final String MEDIA_MP4 = "video/mp4";
    public static final String MEDIA_FLV = "video/x-flv";
    public static final String MEDIA_AVI = "video/x-msvideo";
    public static final String MEDIA_RMVB = "application/vnd.rn-realmedia-vbr";
    public static final String MEDIA_WAV = "audio/x-wav";

    /**
     * 压缩文件类型
     */
    public static final String COMPRESS_RAR = "application/x-rar-compressed";
    public static final String COMPRESS_ZIP = "application/zip";
    public static final String COMPRESS_GZ = "application/gzip";
    public static final String COMPRESS_BZ2 = "application/x-bzip2";
    public static final String COMPRESS_7Z = "application/x-7z-compressed";

    /**
     * 根据扩展名获取MIME类型
     *
     * @param extension 扩展名
     * @return MIME类型
     */
    public static String getMimeType(String extension) {
        if (extension == null) {
            return null;
        }
        String ext = extension.toLowerCase();
        switch (ext) {
            case "png":
                return IMAGE_PNG;
            case "jpg":
            case "jpeg":
                return IMAGE_JPEG;
            case "bmp":
                return IMAGE_BMP;
            case "gif":
                return IMAGE_GIF;
            case "pdf":
                return DOC_PDF;
            case "doc":
                return DOC_MSWORD;
            case "docx":
                return DOC_DOCX;
            case "xls":
                return DOC_MSEXCEL;
            case "xlsx":
                return DOC_XLSX;
            case "ppt":
                return DOC_MSPPT;
            case "pptx":
                return DOC_PPTX;
            case "txt":
                return DOC_TXT;
            case "mp3":
                return MEDIA_MP3;
            case "mp4":
                return MEDIA_MP4;
            case "flv":
                return MEDIA_FLV;
            case "avi":
                return MEDIA_AVI;
            case "rmvb":
                return MEDIA_RMVB;
            case "wav":
                return MEDIA_WAV;
            case "rar":
                return COMPRESS_RAR;
            case "zip":
                return COMPRESS_ZIP;
            case "gz":
                return COMPRESS_GZ;
            case "bz2":
                return COMPRESS_BZ2;
            case "7z":
                return COMPRESS_7Z;
            default:
                return "application/octet-stream";
        }
    }
} 